// 享元动作
var FlyWeight = {
  moveX(x) {
    this.x = x;
  },
  moveY(y) {
    this.y = y;
  }
}
// 角色类
var Player = function(x, y, c) {
  this.x = x;
  this.y = y;
  this.color = c;
}
Player.prototype = FlyWeight;
Player.prototype.changeC = function(c) {
  this.color = c;
}
// 精灵类
var Spirit = function(x, y, r) {
  this.x = x;
  this.y = y;
  this.r = r;
}
Spirit.prototype = FlyWeight;
Spirit.prototype.changeR = function(r) {
  this.r = r;
}

// 测试
var player = new Player(5, 6, 'red');
console.log(player);
player.moveX(6);
player.moveY(7);
player.changeC('pink');
console.log(player);

var spirit = new Spirit(2, 3, 4);
console.log(spirit);
spirit.moveX(3);
spirit.moveY(4);
spirit.changeR(5);
console.log(spirit);


